// #include <bits/stdc++>
#include <bits/stdc++.h>
using namespace std;

struct TreeNode
{
    TreeNode *left;
    TreeNode *right;
};
class Solution
{
  public:
    int ans;
    int dfs(TreeNode *cur)
    {
        if (!cur)
            return 0;
        int left = dfs(cur->left);
        if (left == -1)
            return -1;
        int right = dfs(cur->right);
        if (right == -1)
            return -1;
        if (abs(right - left) > 1)
            return -1;
        return max(right, left) + 1;
    }
    bool IsBalanced_Solution(TreeNode *pRoot)
    {
        return dfs(pRoot) != -1;
    }
};
